package tools;

import httptools.HttpJsonTool;

import java.util.HashMap;
import java.util.Map;

import com.cqtczh.qhd.driver.api.GagApi;
import com.google.gson.Gson;

import android.content.Context;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Handler;
import android.os.Message;
import android.util.Log;

/** 
 * @author  作者 E-mail: 
 * @date 创建时间：2015-6-30 下午5:34:28 
 * @version 1.0 
 * @parameter  
 * @since  
 * @return  
 */
public class CheckVersion {

	public static void check(Context context,final Handler mhandler){
		try {
			final int verCode = context.getPackageManager().getPackageInfo(context.getPackageName(), 0).versionCode;
			Log.v("当前版本", ""+verCode);
			Map<String, Object> dataMap = new HashMap<String, Object>();
			dataMap.put("versionNumber", verCode + "");
			HttpJsonTool httpJsonTool=new HttpJsonTool(context);
			httpJsonTool.SetOnLister(new Handler(){
				@Override
				public void handleMessage(Message msg) {
					// TODO Auto-generated method stub
					super.handleMessage(msg);
					if (msg.what==1) {
						if (verCode==Integer.parseInt((String)msg.obj)) {
							mhandler.sendEmptyMessage(0);
						} else {
							//有更新
							mhandler.sendEmptyMessage(1);
						}
					}
				}
			});
			httpJsonTool.StartWork(dataMap, GagApi.CheckVersion, null, null);
		} catch (NameNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	
}
